#ifndef INDEX_ITERATOR_H_INCLUDED
#define INDEX_ITERATOR_H_INCLUDED

class index_iterator
{
private:
//public:
    typedef TID iterType;
    typedef vector<iterType> storeType;
    typedef storeType::iterator storeIter;

    storeType* content;
    unsigned current;

    index_iterator() : content(NULL), current(0) {}
    index_iterator(storeType newContent) : content(new storeType(newContent)), current(0) {}
    index_iterator(unsigned position) : content(NULL), current(position) {} // Only used for creating end()

    index_iterator(const index_iterator& other) = delete;
    index_iterator operator=(const index_iterator& other) = delete;

    friend class Leaf;
    friend class Node;
    friend class InnerNode;


public:
    index_iterator(index_iterator&& dontCare) : content(dontCare.content), current(dontCare.current)
    {
        dontCare.content = 0;
    }

    void add(index_iterator&& other)
    {
        if(content && other.content)
        {
            storeIter t_e = content->end();
            storeIter o_b = other.content->begin();
            storeIter o_e = other.content->end();
            content->insert(t_e, o_b, o_e);
            //content->insert(content->end(), other.content->begin(), other.content->end());
        }
        else if(other.content)
        {
            content = new storeType(*(other.content));
        }

        current = 0;
    }

    index_iterator end()
    {
        if(content)
            return index_iterator(content->size());
        else
            return index_iterator(0);
    }

    index_iterator& operator++()
    {
        current++;
        return *this;
    }

    index_iterator& operator++(int)
    {
        current++;
        return *this;
    }

    bool operator==(const index_iterator& rhs)
    {
        return current == rhs.current;
    }

    bool operator!=(const index_iterator& rhs)
    {
        return current != rhs.current;
    }

    iterType& operator*()
    {
        return content->at(current);
    }

    ~index_iterator()
    {
        delete content;
    }
};

#endif // INDEX_ITERATOR_H_INCLUDED
